#pragma once
#include "EventEngine.h"
#include "Core/Market/MarketDataEngine.h"
#include "Core/Redis/RedisWrapper.h"
#include "Core/Market/BarGenerator.h"
#include "Core/Market/HistoryDataEngine.h"
#include "TrTypes.h"
#include <QObject>
#include <QTimer>

namespace Market {

using BarData = std::pair<std::string, WTSBarStruct>;

class MarketService : public QObject {
    Q_OBJECT
public:
    explicit MarketService(QObject* parent = nullptr);
    ~MarketService();
    
    // 初始化服务
    bool init(const QString& configPath = QString());
    
    // 启动服务
    void start();
    
    // 停止服务
    void stop();
    
private:
    bool m_initialized{false};
    QString m_configPath;
    
    // 事件处理器
    void handleTick(const Event& event);
    void handleBar(const Event& event);
    void handleMarketConnected(const Event& event);
    void handleMarketDisconnected(const Event& event);
    
    // 定时任务
    void handleDailyTask();
    
    // 历史数据同步处理
    void handleSyncCompleted();
    void handleSyncFailed(const QString& error);
    
    
    QTimer* m_dailyTimer{nullptr};  // 每日定时器
    bool m_running{false};          // 运行状态
};

} // namespace Market